<?php
if ($_POST) {
    include_once("../../Functions/connectDatabase.php");
    include_once("../../Functions/fileSystem.php");
    get_connection();
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $id = $_POST["id"];
        $count = $_POST["count"];
        $attachment=$_POST["attachment"];
        if ($count == 0) {
            $sql = "DELETE FROM news WHERE news_id='$id'";
            delete("../../Public/Uploads/", $attachment);
            if (mysqli_query($conn, $sql)) {
                echo "<script>alert('删除成功！');window.location.href='./adminShow.php'</script>";
            } else {
                $error = mysqli_error($conn);
                $error = str_replace('\'', '', $error);
                echo "<script>alert('删除失败！$error');window.location.href='./adminShow.php'</script>";
            }
        } else {
            echo "<script>alert('删除失败！该新闻下的评论数不为0！');window.location.href='./adminShow.php'</script>";
        }
    }
    close_connection();
}
?>